package Data;

import JDBC.DBUtil;

import javax.print.DocFlavor;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * description:
 * author: 柳胜酉
 * 2022/7/9
 */
public class Util {

    public static void setTimer(JLabel time) {
        final JLabel varTime = time;
        Timer timeAction = new Timer(100, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                long timemillis = System.currentTimeMillis();
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                varTime.setText(df.format(new Date(timemillis)));
            }
        });
        timeAction.start();
    }

    public static boolean checkByUnameAndPwd(String sno, String pwd, String table) {
        String no = null;
        String password = null;
        if (table == "user_info") {
            no = "s_no";
            password = "s_password";
        } else if (table == "user_info_t") {
            no = "t_no";
            password = "t_password";
        } else if (table == "user_info_m") {
            no = "m_no";
            password = "m_password";
        }
        String sql = "select * from " + table + " where " + no + " ='" + sno + "' and " + password + "='" + pwd + "' ";
        ResultSet rs = DBUtil.getResult(sql);
        boolean flag = false;
        try {
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }

    public static String getCount(String count){
        String Count = count;
        return Count;
    }
}